<?php
  session_cache_limiter('private,must-revalide');
  if ($_POST["Submit"])
  {
	 $user_name = $_POST["user_name"];
	 $user_password = md5(trim($_POST['user_password']));
	 $user_email = $_POST["user_email"];  //E-mail
	 $user_realname = $_POST["user_realname"];  //姓名

	 //權限
	 $p0 = $_POST["p0"]; 
	 $p6 = $_POST["p6"]; 
	 $p7 = $_POST["p7"]; 
	 $p8 = $_POST["p8"]; 
	 $p9 = $_POST["p9"]; 
	 $p10 = $_POST["p10"]; 
	 $p12 = $_POST["p12"]; 
	 $p13 = $_POST["p13"]; 
	 $p14 = $_POST["p14"]; 

	 if($p0==''&$p6==''&$p7==''&$p8==''&$p9==''&$p10==''&$p12==''&$p13==''&$p14=='')
	 {
		MyNotice("該用戶必須具有一個欄目的權限!");
		exit();
	 }

	 $permission= $p0.','.$p6.','.$p7.','.$p8.','.$p9.','.$p10.','.$p12.','.$p13.','.$p14;

	 // 检测用户名
	 $query = "SELECT * FROM $TBL_USERS WHERE user_name='$user_name'";
	 if ( do_query($query,1) > 0)
	 {
	   MyNotice("该用户名已经存在,请重新输入");
	   exit(0);    
	 }

	  if ($_POST['user_password']=='')
	 {
	   MyNotice("请输入密码！");
	   exit(0);    
	 }

     //检测邮箱
	 $query = "SELECT * FROM $TBL_USERS WHERE user_email!='' AND user_email='$user_email'";
	 if ( do_query($query,1) > 0)
	 {
		 MyNotice("该邮箱已有人使用,请换一个试试!");
		 exit;
	 }

	 //获取最大的用户ID
     $query = "SELECT MAX(`user_id`) FROM $TBL_USERS";
	 $max_user_id = do_query($query,3) + 1;

	 
	 

	//步骤1: 插入到用户表
	 $query = "INSERT INTO $TBL_USERS SET user_id='$max_user_id',user_name='$user_name',user_password='$user_password',user_realname='$user_realname',user_email='$user_email',user_type='1',permission='$permission',user_regdate='".get_Now()."'";
	 mysql_query($query,$con) or die("出错了: 1");      
	 MyNotice("管理员添加成功",2, "member.php");    
     exit(0);
  }
  $tpl = new PhplibTpl("templates");
  $tpl -> set_file("main", "add_member.htm");
  $tpl -> set_var( $conf);
  $tpl -> parse("Out_main", "main");
  $tpl -> p("Out_main");
  exit(0);
?> 